<?php

class Image_Data_Mapper
{
    
private $result = null;
private $errors = null;
    

    public function save( Image_Model $model)
    {
        $db = Db_Helper::getInstance();
        $sql1 = "
                INSERT INTO images (userId, pathToFull, pathToThumb, timeCreated)
                VALUES(
                    '" . $model->getUserId()  . "',
                    '" . $model->getPathToFull()  . "',
                    '" . $model->getPathToThumb()  . "',
                    '" . $model->getTimeCreated()  . "'
                    )";
        if(!$db->insert($sql1)) {
            $this->errors = QUERY_ERROR;
            return false;
        } else{
            $sql2="
                UPDATE users
                SET picture ='" . $model->getPathToThumb() . "'
                WHERE id = " . $model->getUserId() . "
                LIMIT 1
                    ";
            if(!$db->update($sql2)) {
                $this->errors = QUERY_ERROR ;
                return false;
            } else {
                return true;
            }                  
        }
    }
    
    public function getErrors()
    {
       return $this->errors; 
    }
    
       
}
